/**
 * Copyright 2025 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

@import url("./spectrum-button.css");
@import url("./button-overrides.css");

@media (forced-colors: active) {
    :host([treatment][disabled]) {
        border-color: graytext;
    }

    :host([treatment]:not([disabled]):hover) {
        border-color: highlight;
    }

    :host(.remove-focus-ring-safari-hack:focus-visible):after {
        forced-color-adjust: none;
        box-shadow: none;
    }
}

@keyframes show-progress-circle {
    0% {
        visibility: hidden;
    }

    100% {
        visibility: visible;
    }
}

@keyframes hide-icons-label {
    0% {
        visibility: visible;
    }

    100% {
        visibility: hidden;
    }
}

@keyframes update-pending-button-styles {
    100% {
        background-color: var(--highcontrast-button-background-color-disabled, var(--mod-button-background-color-disabled, var(--spectrum-button-background-color-disabled)));
        border-color: var(--highcontrast-button-border-color-disabled, var(--mod-button-border-color-disabled, var(--spectrum-button-border-color-disabled)));
        color: var(--highcontrast-button-content-color-disabled, var(--mod-button-content-color-disabled, var(--spectrum-button-content-color-disabled)));
    }
}

:host([pending]:not([disabled])) {
    cursor: default;
    pointer-events: none;
    animation: update-pending-button-styles 0s var(--pending-delay, 1s) forwards;
}

::slotted([slot="icon"]) {
    /* Correct CSS output taking too much control of this element */
    visibility: revert-layer;

    --mod-progress-circle-position: relative;
    --spectrum-icon-size: inherit;
}

sp-progress-circle {
    display: block;
    visibility: hidden;
    position: absolute;
    left: 50%;
    transform: translate(-50%, 0);
}

:host([pending]:not([disabled])) sp-progress-circle {
    animation: show-progress-circle 0s var(--pending-delay, 1s) forwards;
}

:host([pending]:not([disabled])) slot[name="icon"],
:host([pending]:not([disabled])) #label {
    animation: hide-icons-label 0s var(--pending-delay, 1s) forwards;
}

:host(.remove-focus-ring-safari-hack:focus-visible):after {
    margin: calc(-1 * var(--mod-button-focus-indicator-gap, var(--mod-focus-indicator-gap, var(--spectrum-focus-indicator-gap))));
    box-shadow: none;
}

:host(.remove-focus-ring-safari-hack:focus-visible) {
    box-shadow: none;
    outline: none;
}

:host(.remove-focus-ring-safari-hack:focus-visible:not(:hover)) {
    background-color: var(--highcontrast-button-background-color-default, var(--mod-button-background-color-default, var(--spectrum-button-background-color-default)));
    border-color: var(--highcontrast-button-border-color-default, var(--mod-button-border-color-default, var(--spectrum-button-border-color-default)));
    color: var(--highcontrast-button-content-color-default, var(--mod-button-content-color-default, var(--spectrum-button-content-color-default)));
}
